<template>
  <div class="login_body">
    <div class="login_background"></div>
    <div class="login_box second_height">
      <!-- 头像区域 -->
      <div class="avator_box">
        <img src="../assets/logo.png" />
      </div>
      <!-- 登录表单区域 -->
      <Form class="login_form" :model="loginForm" :rules="loginRules" ref="loginRuleForm">
        <div class="span-title-font">
          <span>人脸系统后台登陆</span>
        </div>
        <!-- 用户名 -->
        <FormItem prop="admin_acc">
          <Input
            placeholder="请输入用户名"
            type="text"
            size="large"
            v-model="loginForm.admin_acc"
            @keyup.enter.native="searchFile"
            prefix="ios-contact"
          />
        </FormItem>
        <!-- 密码 -->
        <FormItem prop="admin_pwd">
          <Input
            placeholder="请输入密码"
            type="password"
            password
            size="large"
            @keyup.enter.native="searchFile"
            v-model="loginForm.admin_pwd"
            prefix="md-lock"
          />
        </FormItem>
        <!-- 验证码 -->
        <FormItem class="flex-img" prop="captcha">
          <Input
            placeholder="请输入验证码"
            @keyup.enter.native="searchFile"
            type="text"
            size="large"
            v-model="loginForm.captcha"
          />
          <span class="img-form-captch" @click="handleChangeCaptch()">
            <img :src="imgUrl" />
          </span>
        </FormItem>
        <!-- 按钮区域 -->
        <FormItem class="btns">
          <Button
            type="primary"
            size="large"
            @click="loginSubmitForm()"
            style="margin-right:10px"
          >确定</Button>
          <Button type="info" size="large" @click="resetLoginForm()">重置</Button>
        </FormItem>
        <!-- <el-divider></el-divider> -->
      </Form>
    </div>
  </div>
</template>
<script>
import { mapActions } from 'vuex'
export default {
  data() {
    return {
      imgUrl: '',
      count: '',
      // 获取输入的手机号
      phone: '',
      timer: null,
      loginForm: {
        admin_acc: '',
        admin_pwd: '',
        captcha: '',
        captch_key: ''
      },
      loginRules: {
        admin_acc: [
          { required: true, message: '请输入用户名称', trigger: 'blur' }
        ],
        admin_pwd: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' }
        ],
        captcha: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
      }
    }
  },
  methods: {
    ...mapActions(['togetActiveName']),
    // 登录
    loginSubmitForm() {
      this.$refs.loginRuleForm.validate(async valid => {
        if (valid) {
          //   const { data: res } = await this.$http.post(
          //     'Api/Login/loginCheck.php',
          //     this.$util.toParams(this.loginForm)
          //   )
          //   // console.log(res.data)
          //   if (res.code !== 1) {
          //     return this.$message.error(res.msg)
          //   }
          // console.log(res.data)
          // 把token令牌,manager_id存储到sessionStorage
          //   const str = {
          //     token: res.data.token,
          //     manager_id: res.data.manager_id
          //   }
          // console.log(str)
          //   window.sessionStorage.setItem('token', JSON.stringify(str))
          //   // window.sessionStorage.removeItem('login_name')
          //   // window.sessionStorage.removeItem('login_password')
          //   window.sessionStorage.setItem('user_name', res.data.user_name)
          this.$Message.success('登陆成功')
          this.$router.push('/person')
          window.sessionStorage.setItem('activeName', 'person')
          this.togetActiveName('person')
          //   window.sessionStorage.setItem('navState', '/welcome')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    // 重置
    resetLoginForm() {
      this.$refs.loginRuleForm.resetFields()
      if (window.sessionStorage.getItem('login_name') !== '') {
        // window.sessionStorage.setItem('login_name', this.loginForm.login_name)
        window.sessionStorage.removeItem('login_name')
      }
      if (window.sessionStorage.getItem('login_passwd') !== '') {
        window.sessionStorage.removeItem('login_password')
      }
      // this.onRefresh()
      // console.log(this.$refs)
    },
    onRefresh() {
      this.msg = ''
      this.isTrue = false
      // this.$refs.slideblock.reset()
    },
    handleChangeCaptch() {
      if (this.loginForm.admin_acc !== '') {
        window.sessionStorage.setItem('login_name', this.loginForm.admin_acc)
      }
      if (this.loginForm.admin_pwd !== '') {
        window.sessionStorage.setItem('login_passwd', this.loginForm.admin_pwd)
      }
      this.loginForm.captcha = ''
      this.aa()
    },
    // 随机生成8位数字
    aa() {
      var a = Math.round(Math.random() * 100000000)
      // this.key = a
      this.loginForm.captch_key = a
      this.imgUrl =
        'http://dangxiao2.renxiang123.cn/Api/Login/captcha.php?key=' + a
    },
    // 监听点击键盘登陆事件
    searchFile() {
      this.loginSubmitForm()
    }
  },
  created() {
    if (window.sessionStorage.getItem('login_name') !== '') {
      // console.log(window.sessionStorage.getItem('login_name'))
      // window.sessionStorage.setItem('login_name', this.loginForm.login_name)
      this.loginForm.admin_acc = window.sessionStorage.getItem('login_name')
    }
    if (window.sessionStorage.getItem('login_passwd') !== '') {
      this.loginForm.admin_pwd = window.sessionStorage.getItem('login_passwd')
    }
    this.aa()
  }
}
</script>
<style lang="less" scoped>
@height: 500px;
@secondHeight: 380px;
.login_container {
  // background-color: #2b4b6b;
  // background-image: url(../assets/img/6441-fyssmmc7363710.jpg);
  background-repeat: no-repeat; //不重复
  background-size: 100% 100%; // 满屏
  animation: cloud_three 100s linear infinite;
  height: 100%;
}
.login_body {
  width: 100%;
  height: 100%;
  background: #1c77ac;
  display: flex;
  justify-content: center;
  align-items: center;

  // overflow-x: hidden;
}
.login_background {
  background: url(../assets/img/background.png) no-repeat center;
  background-size: 100% 100%;
  height: 100%;
  width: 300%;
  // overflow-x: hidden;
  animation: cloud_three 100s linear infinite;
  transform: translate3d(0, 0, 0);
  position: absolute;
  top: 0;
  left: 0;
}
@-webkit-keyframes cloud_three {
  0% {
    left: 0;
  }
  100% {
    left: -200%;
  }
}
@-moz-keyframes cloud_three {
  0% {
    left: 0;
  }
  100% {
    left: -200%;
  }
}
@keyframes cloud_three {
  0% {
    left: 0;
  }
  100% {
    left: -200%;
  }
}
.one_height {
  height: @height;
}
.second_height {
  height: @secondHeight;
}
.login_box {
  // overflow: hidden;
  width: 340px;
  background-color: rgba(0, 0, 0, 0.3);
  border-radius: 5px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  // overflow-x: hidden;
}
// .login-wrap{
//     right: 15%;
//     margin: auto;
//     width: 500px;
//     height: auto;
//     overflow: hidden;
//     padding-bottom: 30px;
//     text-align: center;
//     background: #14547A;
//     border-radius: 35px;
// }
.avator_box {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 1px solid #eee;
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 5px;
  background-color: #fff;
  box-shadow: 0 0 5px #ddd;

  img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
  }
}
.login_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 15px;
  box-sizing: border-box;
}
.btns {
  display: flex;
  justify-content: flex-end;
}
// 账号密码登陆样式
.span-title-font {
  width: 100%;
  text-align: center;
  color: #409eff;
  padding-bottom: 30px;
}
// 其他登录方式的样式
.other_login_message {
  padding-top: 15px;
  border-top: 1px solid #dcdfe6;
  color: #409eff;
  font-size: 13px;
  img {
    width: 25px;
    height: 25px;
  }
}
.common_login_jusfity {
  display: flex;
  align-items: center;
  cursor: pointer;
  .weixinClass {
    color: #60c84b;
    font-size: 20px;
  }
  .dingdingClass {
    color: #3396fb;
    font-size: 20px;
  }
  span:last-child {
    align-items: center;
    margin-left: 3px;
  }
}
// .wechat_and_dingding_login {
//   display: flex;
//   justify-content: flex-end;
//   margin-left: auto;
// }

// 微信登陆的弹框样式
.wechat_dialog_style {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  span:first-child {
    font-size: 1.8rem;
    margin-bottom: 10px;
  }
  span:last-child {
    width: 380px;
    text-align: center;
    padding: 10px;
    border-radius: 20px;
    margin-top: 10px;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
  }
  div:first-child {
    width: 360px;
    height: 360px;
    border: 1px solid #dcdcdc;
    padding: 20px;
  }
}

// 登陆验证码的样式
.flex-img {
  position: relative;
}
.img-form-captch {
  width: 120px;
  height: 40px;
  position: absolute;
  right: 0;
  img {
    width: 120px;
    height: 40px;
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
  }
}
</style>
